package com.fzt.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fzt.admin.common.convention.result.Result;
import com.fzt.admin.common.convention.result.Results;
import com.fzt.admin.remote.dto.ShortLinkRemoteService;
import com.fzt.admin.remote.dto.req.ShortLinkCreateReqDTO;
import com.fzt.admin.remote.dto.req.ShortLinkPageReqDTO;
import com.fzt.admin.remote.dto.req.ShortLinkUpdateReqDTO;
import com.fzt.admin.remote.dto.resp.ShortLinkCreateRespDTO;
import com.fzt.admin.remote.dto.resp.ShortLinkPageRespDTO;
import org.springframework.web.bind.annotation.*;

@RestController
public class ShortLinkController {

    private final ShortLinkRemoteService shortLinkRemoteService = new ShortLinkRemoteService(){
    };

    /**
     * 远程调用分页查询短链接
     */
    @GetMapping("/api/short-link/admin/v1/page")
    public Result<IPage<ShortLinkPageRespDTO>> pageSHortLink(ShortLinkPageReqDTO reqDTO){
        return shortLinkRemoteService.pageShortLink(reqDTO);
    }

    /**
     * 远程调用创建短链接
     */
    @PostMapping("/api/short-link/admin/v1/create")
    public Result<ShortLinkCreateRespDTO> createShortLink(@RequestBody ShortLinkCreateReqDTO reqDTO){
        return shortLinkRemoteService.createShortLink(reqDTO);
    }

    /**
    * 远程调用修改短链接
     */
    @PutMapping("/api/short-link/admin/v1/update")
    public Result<Void> updateShortLink(@RequestBody ShortLinkUpdateReqDTO reqParam){
        shortLinkRemoteService.updateShortLink(reqParam);
        return Results.success();
    }
}
